package hot100.logos51To60;

import java.util.ArrayList;
import java.util.List;

/**
 * @author logos
 * date 2025/7/15 17:47
 * @version v1.0
 * @Package hot100.logos51To60
 */
public class logos57 {

    /**
     * 57. 电话号码的字母组合
     * https://leetcode.cn/problems/letter-combinations-of-a-phone-number/description/?envType=study-plan-v2&envId=top-100-liked
     */

    class Solution {
        private static final String[] mapping = new String[] { "", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv",
                "wxyz" };

        public List<String> letterCombinations(String digits) {
            List<String> ans = new ArrayList<>();
            int n = digits.length();
            if (n == 0) {
                return ans;
            }
            char[] path = new char[n];
            dfs(0, path, digits.toCharArray(),ans);
            return ans;
        }

        private void dfs(int i, char[] path, char[] digits, List<String> ans) {
            if (i == digits.length) {
                ans.add(new String(path));
                return;
            }
            for (char c : mapping[digits[i] - '0'].toCharArray()) {
                path[i] = c;
                dfs(i + 1, path, digits, ans);
            }
        }
    }
}
